import {
  IDevice,
  IContact,
  IEvent,
  IError,
  IAdditionalData,
  ICommunicationLibrary
} from '../common/commlib.interfaces';
import { Subject } from 'rxjs';
import { ChannelType, DeviceState } from '../common/commlib.enums';

export abstract class Device implements IDevice {
  protected status: string;
  protected type: ChannelType;
  protected state: DeviceState;
  protected contacts: IContact[] = [];
  protected user: any;
  protected address: any;
  protected name: string;
  protected additionalData: IAdditionalData;

  public onNewEvent$: Subject<IEvent> = new Subject<IEvent>();
  public onError$: Subject<IError> = new Subject<IError>();

  public getId(): string {
    return this.id;
  }

  public getStatus(): string {
    return this.status;
  }

  public getState(): DeviceState {
    return this.state;
  }

  public getContacts(): IContact[] {
    return this.contacts;
  }

  public getType(): ChannelType {
    return this.type;
  }

  public getAddress(): any {
    return this.address;
  }

  public getName(): string {
    return this.name;
  }

  public getUser(): string {
    return this.user;
  }

  public getAdditionalData(): IAdditionalData {
    return this.additionalData;
  }

  protected constructor(
    private id: string,
    protected commlib?: ICommunicationLibrary
  ) {}

  public abstract register(parameters?: any): void;
  public abstract unregister(): void;
  public abstract setState(State: DeviceState): void;
  public abstract createContact(parameters?: any): Promise<IContact>;
  public abstract joinContact(contactId: string): Promise<IContact>;
}
